﻿<UserControl x:Class="MergeTool.UI.Views.LoginView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:viewModels="clr-namespace:MergeTool.UI.ViewModels"
             mc:Ignorable="d" 
             d:DesignHeight="600" d:DesignWidth="500">

    <UserControl.Resources>
        <Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="Margin" Value="15,3,3,3" />
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="Width" Value="250"/>
            <Setter Property="Padding" Value="1" />
        </Style>
        <Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
            <Setter Property="Margin" Value="15,3,3,3" />
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="HorizontalAlignment" Value="Left"/>
            <Setter Property="Width" Value="250"/>
        </Style>
        <Style x:Key="LabelLoginStyle" TargetType="Label">
            <Setter Property="Margin" Value="3" />
        </Style>

        <Style x:Key="LoginMessageStyle" TargetType="TextBlock">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="Foreground" Value="Red" />
                </Trigger>
                <Trigger Property="Validation.HasError" Value="False">
                    <Setter Property="Foreground" Value="LimeGreen" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <Style TargetType="{x:Type mui:ModernButton}" x:Name="UserNameButtonsStyle" BasedOn="{StaticResource {x:Type mui:ModernButton}}">
            <Setter Property="EllipseDiameter" Value="24"/>
            <Setter Property="IconWidth" Value="13"/>
            <Setter Property="IconHeight" Value="13"/>
            <Setter Property="Margin" Value="3"/>
        </Style>
        <PathGeometry x:Key="AddIcon">F1 M 35,19L 41,19L 41,35L 57,35L 57,41L 41,41L 41,57L 35,57L 35,41L 19,41L 19,35L 35,35L 35,19 Z</PathGeometry>
        <PathGeometry x:Key="RemoveIcon">F1 M 26.9166,22.1667L 37.9999,33.25L 49.0832,22.1668L 53.8332,26.9168L 42.7499,38L 53.8332,49.0834L 49.0833,53.8334L 37.9999,42.75L 26.9166,53.8334L 22.1666,49.0833L 33.25,38L 22.1667,26.9167L 26.9166,22.1667 Z</PathGeometry>

        <viewModels:LoginViewModel x:Key="LoginViewModel" />
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    </UserControl.Resources>



    <Grid Style="{StaticResource ContentRoot}">
        <ScrollViewer>
            <StackPanel MinWidth="200">
                <TextBlock Text="Login into Team Foundation Server" Style="{StaticResource Heading2}" />
                <Grid Margin="10">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Label Style="{StaticResource LabelLoginStyle}" Grid.Row="0" Grid.Column="0" Content="TFS URI:" />
                    <Label Style="{StaticResource LabelLoginStyle}" Grid.Row="1" Grid.Column="0" Content="Project Collection:" />
                    <Label Style="{StaticResource LabelLoginStyle}" Grid.Row="2" Grid.Column="0" Content="Team Project:" />
                    <Label Style="{StaticResource LabelLoginStyle}" Grid.Row="3" Grid.Column="0" Content="Username:" />
                    <TextBox  Grid.Column="1" Grid.Row="0" Text="{Binding Source={StaticResource LoginViewModel}, Path=TFSUri, Mode=TwoWay}" />
                    <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Source={StaticResource LoginViewModel}, Path=ProjectCollection, Mode=TwoWay}" />
                    <TextBox  Grid.Column="1" Grid.Row="2" Text="{Binding Source={StaticResource LoginViewModel}, Path=TeamProject, Mode=TwoWay}" />
                    <!--<TextBox Style="{StaticResource TextBoxLoginStyle}" Grid.Column="1" Grid.Row="3" Text="{Binding Source={StaticResource LoginViewModel}, Path=UserName, Mode=TwoWay}" />-->
                    <StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
                        <ComboBox  IsEditable="True"
                              ItemsSource="{Binding Source={StaticResource LoginViewModel}, Path= UserNames}"
                              SelectedItem="{Binding Source={StaticResource LoginViewModel}, Path= SelectedUserName}"
                              Text="{Binding Source={StaticResource LoginViewModel}, Path= NewUserName, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                         />
                        <mui:ModernButton IconData="{StaticResource AddIcon}" Command="{Binding Source={StaticResource LoginViewModel}, Path=AddUserCommand, Mode=OneWay}" ToolTipService.InitialShowDelay="500" ToolTip="Add user." />
                        <mui:ModernButton IconData="{StaticResource RemoveIcon}" Command="{Binding Source={StaticResource LoginViewModel}, Path=RemoveUserCommand, Mode=OneWay}" ToolTipService.InitialShowDelay="500" ToolTip="Remove user." />
                    </StackPanel>
                    
                    <Button Margin="0,5,67.6,14.6" HorizontalAlignment="Right" MinWidth="50" Grid.Column="1" Grid.Row="4" Content="Submit" Command="{Binding SubmitCommand, Mode=OneWay, Source={StaticResource LoginViewModel}}" />
                </Grid>

                <TextBlock Style="{StaticResource LoginMessageStyle}" Text="{Binding Source={StaticResource LoginViewModel}, Path=LoginDisplayMessage, Mode=TwoWay,
                    UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" FontWeight="Medium" TextWrapping="Wrap" Width="300" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Center">
                    <Validation.ErrorTemplate>
                        <ControlTemplate>
                        </ControlTemplate>
                    </Validation.ErrorTemplate>
                </TextBlock>
                <mui:ModernProgressRing IsActive="True" Visibility="{Binding SubmitCommand.IsActive, Source={StaticResource LoginViewModel}, Converter={StaticResource BooleanToVisibilityConverter}}" Width="50" Height="50" Style="{Binding Source={StaticResource CircleProgressRingStyle}}" HorizontalAlignment="Center" />
            </StackPanel>
            

        </ScrollViewer>



    </Grid>
</UserControl>
